home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / attemptsemaphore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-12  |  1.9 KB  |  87 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: attemptsemaphore.c,v 1.4 1996/08/13 13:55:58 digulla Exp $
  4.     $Log: attemptsemaphore.c,v $
  5.     Revision 1.4  1996/08/13 13:55:58  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:05  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include "exec_intern.h"
  17.  
  18. /*****************************************************************************
  19.  
  20.     NAME */
  21.     #include <exec/semaphores.h>
  22.     #include <clib/exec_protos.h>
  23.  
  24.     __AROS_LH1(ULONG, AttemptSemaphore,
  25.  
  26. /*  SYNOPSIS */
  27.     __AROS_LHA(struct SignalSemaphore *, sigSem, A0),
  28.  
  29. /*  LOCATION */
  30.     struct ExecBase *, SysBase, 96, Exec)
  31.  
  32. /*  FUNCTION
  33.     Tries to get an exclusive lock on a signal semaphore. If the semaphore
  34.     is already in use by another task this function does not wait but
  35.     return false instead.
  36.  
  37.     INPUTS
  38.     sigSem - Pointer so semaphore structure.
  39.  
  40.     RESULT
  41.     TRUE if the semaphore could be obtained, FALSE otherwise.
  42.  
  43.     NOTES
  44.     The lock must be freed with ReleaseSemaphore().
  45.  
  46.     EXAMPLE
  47.  
  48.     BUGS
  49.  
  50.     SEE ALSO
  51.     ReleaseSemaphore()
  52.  
  53.     INTERNALS
  54.  
  55.     HISTORY
  56.     29-10-95    digulla automatically created from
  57.                 exec_lib.fd and clib/exec_protos.h
  58.     21-01-96    fleischer implementation
  59.  
  60. *****************************************************************************/
  61. {
  62.     __AROS_FUNC_INIT
  63.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  64.  
  65.     LONG ret=0;
  66.  
  67.     /* Arbitrate for semaphore nesting count and owner fields */
  68.     Forbid();
  69.  
  70.     /* If the semaphore is free or the user is the current task */
  71.     if(!sigSem->ss_NestCount||sigSem->ss_Owner==SysBase->ThisTask)
  72.     {
  73.     /* Get an exclusive lock on it */
  74.     ObtainSemaphore(sigSem);
  75.  
  76.     /* And return true */
  77.     ret=1;
  78.     }
  79.  
  80.     /* All done */
  81.     Permit();
  82.     return ret;
  83.  
  84.     __AROS_FUNC_EXIT
  85. } /* AttemptSemaphore */
  86.  
  87.